package com.zlc.platform.controller;


import com.zlc.common.annotation.LogSaveAnnotation;
import com.zlc.common.common.constant.PlatConstant;
import com.zlc.common.common.entity.PageVo;
import com.zlc.common.core.sys.model.vo.MayanPlatDicVo;
import com.zlc.common.model.sys.DicPageRequest;
import com.zlc.platform.model.DicEntity;
import com.zlc.platform.service.DicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "数据字典相关")
@RestController
@RequestMapping("/api/dic")
public class DicController {

    @Autowired
    private DicService dicService;

    /**
     * 分页查询字典
     */
    @ApiOperation(value = "查询字典")
    @PostMapping(value = "/queryDicList")
    public PageVo<MayanPlatDicVo> queryDicList(@RequestBody DicPageRequest pageRequest) {
        return dicService.queryDicList(pageRequest);
    }


    @ApiOperation(value = "查询字典")
    @PostMapping(value = "/queryDics")
    public List<DicEntity> queryDicList(@RequestBody List<String> codes) {
        return dicService.queryDics(codes);
    }

    /**
     * 添加字典
     */
    @ApiOperation(value = "新增字典")
    @PostMapping(value = "/addDic")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "新增字典", catalog = "基础配置/数据字典")
    public void addDic(@RequestBody MayanPlatDicVo dicVo){
        dicService.addDic(dicVo);
    }

    /**
     * 修改字典
     */
    @ApiOperation(value = "更新字典")
    @PostMapping(value = "/updateDic")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "更新字典", catalog = "基础配置/数据字典")
    public void updateDic(@RequestBody MayanPlatDicVo dicVo){
        dicService.updateDic(dicVo);
    }


    /**
     * 修改字典状态
     */
    @ApiOperation(value = "修改字典状态")
    @PostMapping(value = "/changeDicStatus")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "修改字典状态", catalog = "基础配置/数据字典")
    public void changeDicStatus(@RequestBody MayanPlatDicVo dicVo){
        dicService.changeDicStatus(dicVo);
    }


    /**
     * 删除字典
     */
    @ApiOperation(value = "删除字典")
    @PostMapping(value = "/removeDic")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "删除字典", catalog = "基础配置/数据字典")
    public void removeDic(@RequestBody Map<String,String> map){
        dicService.removeDic(map.get("id"));
    }
}
